package com.wc.alorithm_blue_bridge._模拟.Q3223;

import java.util.Scanner;

/**
 * @Author congege
 * @Description
 *
 * 出列
 * https://www.lanqiao.cn/problems/3223/learning/?page=1&first_category_id=1
 * @Date Created in 2023/11/25-17:31
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Node head = new Node(0);
        Node pre = head;
        for (int i = 1; i <= n; i++) {
            pre.next = new Node(i);
            pre = pre.next;
        }
        pre = head;
        while (head.next.next != null) {
            while (pre!=null && pre.next != null) {
                remove(pre);
                pre = pre.next;
            }
            pre = head;
        }
        System.out.println(head.next.val);
    }

    static class Node {
        int val;

        public Node(int val) {
            this.val = val;
        }

        Node next;
    }

    static void remove(Node node) {
        node.next = node.next.next;
    }
}
